import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author 03010570
 * @date 2020/07/08
 * describe:    LeetCode : 剑指Offer 03、数组中重复的数字  https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/
 */
public class LeetCode_sword_offer_05 {
    public static void main(String[] args) {
        String s = "We are happy.";
        System.out.println(replaceSpace(s));
    }

    /**
     *  利用 StringBuilder 进行字符串拼接
     *  时间复杂度 ： O(n) ,字符串长度
     *  空间复杂度 ： O(n)
     * @param s
     * @return
     */
    public static String replaceSpace(String s) {
        int length = s.length();
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            if (s.charAt(i) == ' ') {
                builder.append("%20");
            } else {
                builder.append(s.charAt(i));
            }
        }
        return builder.toString();
    }

}
